#define _CRT_SECURE_NO_WARNINGS

struct ListNode {
    int val;
    struct ListNode* next;
    
};

 struct ListNode*mA=headA;
 struct ListNode*mB=headB;
 if(Anum>=Bnum)
 {
     int mov=Anum-Bnum;
     while(mov)
     {
         mA=mA->next;
         mov--;
     }
     while(mA)
     {
        if(mA==mB)
        return mA;
            mA=mA->next;
            mB=mB->next;
     }
 }
 else
 {
     int mov=Bnum-Anum;
     while(mov)
     {
         mB=mB->next;
         mov--;
     }
     while(mB)
     {
        if(mA==mB)
        return mA;
            mA=mA->next;
            mB=mB->next;
     }
 }

 struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
     struct ListNode* Atail = headA;
     struct ListNode* Btail = headB;
     int Anum = 1;
     int Bnum = 1;
     while (Atail->next)
     {
         Anum++;
         Atail = Atail->next;
     }
     while (Btail->next)
     {
         Bnum++;
         Btail = Btail->next;
     }

     if (Atail != Btail)
     {
         return NULL;
     }

     struct ListNode* longlist = headA;
     struct ListNode* shortlist = headB;
     int mov = abs(Anum - Bnum);

     if (Anum < Bnum)
     {
         longlist = headB;
         shortlist = headA;
     }

     while (mov--)
     {
         longlist = longlist->next;
     }

     while (longlist != shortlist)
     {

         longlist = longlist->next;
         shortlist = shortlist->next;
     }

     return longlist;
 }


 bool hasCycle(struct ListNode* head)
 {
     struct ListNode* slow = head;
     struct ListNode* fast = head;
     while (fast && fast->next)
     {
         fast = fast->next->next;
         slow = slow->next;
         if (fast == slow)
             return true;
     }
     return false;
 }